import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/main_page/home/notes/note_detail_page.dart';
import 'package:flutter_douban/model/knowledge_model.dart';

class KnowledgeCell extends StatelessWidget {
  final KnowledgeModel model;
  KnowledgeCell({required this.model});

  @override
  Widget build(BuildContext context) {

    return InkWell(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          Container(
              color: AppColors.page,
              child: ClipRRect(
                child: CachedNetworkImage(
                  imageUrl: model.image!,
                  fit: BoxFit.cover,
                ),
                borderRadius: BorderRadius.circular(6),
              )),
          Container(
            padding: EdgeInsets.all(5),
            child: Text(
              model.name!,
              style: TextStyle(
                color: AppColors.black,
                fontSize: 14,
              ),
              maxLines: 2,
              overflow: TextOverflow.ellipsis,
            ),
          ),
          Container(
            padding: EdgeInsets.only(left: 5, right: 10, bottom: 5),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[_leftView(), _joinView()],
            ),
          )
        ],
      ),
      onTap: (){
        Navigator.of(context).push(MaterialPageRoute(builder: (_) {
          // if(model.note?.video_url?.isNotEmpty == true){
          //   return WindowVideoPage(playType: PlayType.network, dataSource:model.note!.video_url!,id: int.parse(model.note!.id!),);
          // }else{
          //  
          // }
          return NoteDetailPage(id:int.parse(model.note_id!),);
        }));

      },
    );
  }

  Widget _leftView() {
    return Row(
      children: [
        Container(
          width: 24,
          height: 24,
          decoration: BoxDecoration(
            color: AppColors.page,
            borderRadius: BorderRadius.circular(12),
          ),
          child: ClipOval(
            child: FadeInImage.assetNetwork(
              placeholder: 'assets/images/common/lazy-1.png',
              image: model.headicon!,
              fit: BoxFit.cover,
              width: 18,
              height: 18,
            ),
          ),
        ),
        SizedBox(
          width: 5,
        ),
        Container(
          child: Text(
            model.nickname!,
            style: TextStyle(fontSize: 11, color: AppColors.qianTextColor),
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
          ),
        )
      ],
    );
  }

  Widget _joinView() {
    return Row(
      children: [
        Image.asset(
          'assets/images/common/question_comment_unlike_7@2x.png',
          width: 14,
          height: 14,
        ),
        SizedBox(
          width: 5,
        ),
        Text(
          model.likenum!.toString(),
          style: TextStyle(fontSize: 13, color: AppColors.qianTextColor),
        ),
      ],
    );
  }
}
